package itsm.isperp.module.controller.change; 

import javax.servlet.http.HttpServletRequest;

import itsm.isperp.framework.data.domain.DataResponse;
import itsm.isperp.framework.web.controller.BaseController;
import itsm.isperp.framework.web.request.JqGridFilterRuleOp;
import itsm.isperp.framework.web.request.JqGridRequest;
import itsm.isperp.module.entity.change.ChgChangeConfiguration;
import itsm.isperp.module.service.change.ChgChangeConfigurationService;
  
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.stereotype.Controller; 
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 控制器
 * 
 * @author lizx
 * @date 2015-04-27 15:18
 */
@Controller
@RequestMapping("change/changeConfiguration")
public class ChgChangeConfigurationController extends BaseController<ChgChangeConfiguration> {

	@Autowired
	protected ChgChangeConfigurationService chgChangeConfigurationService;

	@Override
	public ChgChangeConfigurationService getService() {
		return this.chgChangeConfigurationService;
	}
	
	@Override
	public String getPageTitle() {
		return "变更资产";
	}
	
	@RequestMapping("listCiChangeProperty")
	@ResponseBody
	public DataResponse<ChgChangeConfiguration> listCiChangeProperty(HttpServletRequest req) {
		String changeId = req.getParameter("changeId");
		JqGridRequest request=new JqGridRequest();
		request.setSort("is_category_proprety", Direction.ASC);
		request.addFilterRule("change_id", JqGridFilterRuleOp.eq, changeId);
		request.setSearchString(" (status<>0 or status is null) and ((is_category_proprety=0 and COLUMNKEY in (select column_name from db_entity_field where use_for_change=1)) or is_category_proprety=1)");
		return this.getService().findAll(request);
	}
	
	@RequestMapping("listAllCiChangeProperty")
	@ResponseBody
	public DataResponse<ChgChangeConfiguration> listAllCiChangeProperty(HttpServletRequest req) {
		String changeId = req.getParameter("changeId");
		JqGridRequest request=new JqGridRequest();
		request.setSort("is_category_proprety", Direction.ASC);
		request.addFilterRule("change_id", JqGridFilterRuleOp.eq, changeId);
		request.setSearchString(" ((is_category_proprety=0 and COLUMNKEY in (select column_name from db_entity_field where use_for_change=1)) or is_category_proprety=1)");
		return this.getService().findAll(request);
	}
	
	
}
